import {
	set
} from '@/utils/lodash-es';

export function genMessage(langs, prefix = 'lang', langCode = 'lang') {
	const obj = {};
	
// #ifndef VUE3
	langs.keys().forEach((key) => {
		const langFileModule = langs(key)["default"];
// #endif
// #ifdef VUE3
	Object.keys(langs).forEach((key) => {
		const langFileModule = langs[key].default;
// #endif
		let fileName = key.replace(`./${prefix}/`, '').replace(/^\.\//, '');
		const lastIndex = fileName.lastIndexOf('.');
		fileName = fileName.substring(0, lastIndex);
		const keyList = fileName.split('/');
		// moduleName = keyList.shift();
		const moduleName = langCode;
		const objKey = keyList.join('.');

		if (moduleName) {
			if (objKey) {
				set(obj, moduleName, obj[moduleName] || {});
				set(obj[moduleName], objKey, langFileModule);
			} else {
				set(obj, moduleName, langFileModule || {});
			}
		}
	});
	// console.log(obj);
	return obj;
}
